home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / uw201.zip / UW_DEMO.C < prev    next >
Text File  |  1991-10-06  |  43KB  |  1,311 lines

  1. #include <stdlib.h>
  2. #include <dos.h>
  3. #include <stdio.h>
  4.  
  5. #ifdef M_I86
  6.     #include <malloc.h>
  7.     #include <graph.h>
  8. #else
  9.     #include <alloc.h>
  10. #endif
  11.  
  12. #include <conio.h>
  13. #include <time.h>
  14. #ifdef __TURBOC__
  15. #include <graphics.h>
  16. #endif
  17. #include "uw.h"
  18. #include "uw_globx.h"
  19. #include "uw_keys.h"
  20.  
  21. #define NUM_WINS 26
  22.  
  23. typedef struct fields_struct                        /* structure for field input to the    */
  24. {                                                                                /* order form function!                            */
  25.     int        num_fields;                                            /* total number of fields                        */
  26.     char    *input[10];                     /* strings for the result                        */
  27.     char    *mask[10];                      /* masks for display on the screen    */
  28.     char    *template[10];                  /* tempatess for validation                    */
  29.     int        x[10];                          /* positions for the input                    */
  30.     int        y[10];
  31.     int        strip[10];                      /* strip masks on result?                        */
  32. } FIELDS;
  33.  
  34. char *Enque_strs[] =
  35. {
  36.     "EnQue Software",
  37.     "Route 1, Box 116C",
  38.     "Pleasant Hill, MO, 64080",
  39.     "24-Hour BBS (816) 353-0991",
  40.     "Voice/Fax (816) 329-6670",
  41.     "(Voice 5-10pm and weekends)"
  42. };
  43. char    *Prices[] = { "39.95", "39.95" };
  44. char    Package[10] = "1", Name[40], Address[40], City[30], State[10],
  45.             Zip[10], Phone[20], Password[10];
  46.  
  47. int tmp();
  48.  
  49. WINDOW    Main_wn, Print_wn[2];
  50. WINDOW     Back_wn, *Back_wnp = &Back_wn;
  51. MENU        Top_menu, *Top_mnp = &Top_menu;
  52. MENU    Terminal_menu, Setup_menu, Window_menu, Files_menu;
  53. MENU        *Drop_mnps[4];
  54.  
  55. int    GraphDriver;        /* The Graphics device driver        */
  56. int    GraphMode;        /* The Graphics mode value        */
  57. int    ErrorCode;        /* Reports any graphics errors        */
  58.  
  59. void init_g(void);
  60. void end_g(void);
  61.  
  62. uchar *Font8x14;
  63. PRINT Printer1, Printer2;
  64.  
  65. main()
  66. {
  67.     int i, r, end_flag = 0, mode_switch = 0;
  68.     WINDOW *wnp;
  69.     char far *dummy;
  70.  
  71.     init_video(80, 25);
  72.     init_mouse();
  73.     init_clock(0x3333);
  74.     wnp = &Main_wn;
  75.     wn_create( 0, 3, V_cols-1, V_rows-1, NO_BDR, WN_NORMAL, wnp );
  76.     wn_color( YELLOW, BLUE, wnp );
  77.     wn_bdr_color( YELLOW, BLUE, wnp );
  78.     wn_name("Main_wn", wnp);
  79.     add_window(wnp);
  80.     title_screen();
  81.     wn_plst( CENTERED, (V_rows / 2) - 1, "Welcome to the UltraWin Library!", wnp );
  82.     if( Ega )
  83.         wn_plst( CENTERED, 3, "UltraWin detects the presence of an EGA compatible board", wnp);
  84.     else if( Vga )
  85.         wn_plst( CENTERED, 3, "UltraWin detects the presence of a VGA compatible board", wnp);
  86.     wait();
  87.  
  88.     wn_clear(wnp);
  89.     wn_color( BLUE, LIGHTGRAY, wnp );
  90.  
  91.     wn_plst(1, 0, "    Speed it one of many features incorporated into the UltraWin Library.     ", wnp );
  92.     wn_plst(1, 1, "   Here is a list of the main features, all of which will be demonstrated!    ", wnp );
  93.  
  94.     wn_color( YELLOW, BLUE, wnp );
  95.     wn_hline(2,SGL_BDR,wnp);
  96.     r = 3;
  97.     wn_plst(0, r++, "1) Complete range of windowing functions to dynamically create, update,", wnp );
  98.     wn_plst(0, r++, "   move, and destroy an unlimited number of windows.", wnp );
  99.     wn_plst(0, r++, "2) A Window Manager that will handle all the hard work when multiple", wnp );
  100.     wn_plst(0, r++, "   windows are on the screen.", wnp );
  101.     wn_plst(0, r++, "3) Each window is fully buffered. Output to a window can take place at any", wnp );
  102.     wn_plst(0, r++, "   time, even if another window overlaps it.  This is perhaps, the", wnp );
  103.     wn_plst(0, r++, "   most impressive feature. Windows can scroll output even if overlapped!", wnp );
  104.     wn_plst(0, r++, "4) Powerful string and data entry capabilities.", wnp );
  105.     wn_plst(0, r++, "5) Powerful menuing capability with full mouse support!", wnp );
  106.     wn_plst(0, r++, "6) The library supports virtually any video board, including 43/50", wnp );
  107.     wn_plst(0, r++, "   row EGA/VGA mode. It even works with non-standard modes i.e. 132*60.", wnp );
  108.     wn_plst(0, r++, "7) UltraWin 2.0 now works in EGA/VGA graphics mode and has user defined", wnp );
  109.     wn_plst(0, r++, "   font capability in both text and graphics modes!", wnp );
  110.     wn_plst(0, r++, "8) EGA/VGA palette control and blink enable/disable to allow all 16", wnp );
  111.     wn_plst(0, r++, "   background colors without foreground blinking.", wnp );
  112.     wn_plst(0, r++, "9) UltraWin 2.0 also has dynamic printer queues that can be either ram", wnp );
  113.     wn_plst(0, r++, "   or disked based and can print to multiple devices in the background!", wnp );
  114.     wn_hline(r,SGL_BDR,wnp);
  115.     wait();
  116.  
  117.     while( !end_flag )
  118.     {
  119.         wn_clear(wnp);
  120.         if( mode_switch )
  121.             show_graphics();
  122.         wn_color( BLUE, LIGHTGRAY, wnp );
  123.         r = 3;
  124.         wn_3d_plst(13, r++, "A) Color/Palette Control", wnp ), r++;
  125.         wn_3d_plst(13, r++, "B) Window Creation      ", wnp ), r++;
  126.         wn_3d_plst(13, r++, "C) Text Line Drawing    ", wnp ), r++;
  127.         wn_3d_plst(13, r++, "D) Window Scrolling     ", wnp ), r++;
  128.         wn_3d_plst(13, r++, "E) Data Entry           ", wnp ), r++;
  129.         r = 3;
  130.         if( EgaVga )
  131.         {
  132.             if( Graphics )
  133.                 wn_3d_plst(43, r++, "F) Switch to Text       ", wnp ), r++;
  134.             else
  135.                 wn_3d_plst(43, r++, "F) Switch to Graphics   ", wnp ), r++;
  136.         }else
  137.                 wn_3d_plst(43, r++, "F) N/A                  ", wnp ), r++;
  138.         wn_3d_plst(43, r++, "G) Drop-down Menus      ", wnp ), r++;
  139.         wn_3d_plst(43, r++, "H) EGA/VGA Text Fonts   ", wnp ), r++;
  140.         wn_3d_plst(43, r++, "I) Print Capabilities   ", wnp ), r++;
  141.         wn_3d_plst(43, r++, "J) All of the Above     ", wnp ), r++;
  142.         r++;
  143.         wn_3d_plst(28, r++, "Q) Quit Demonstration   ", wnp );
  144.  
  145.         wn_prompt("Select desired demo to execute...");
  146.         wn_color( LIGHTGRAY, BLUE, wnp );
  147.         if( mode_switch )
  148.         {
  149.             G_opt = OFF;
  150.             wn_clear(wnp);
  151.             G_opt = ON;
  152.             mode_switch = 0;
  153.         }
  154.         switch( toupper(Event.key) )
  155.         {
  156.             case 'Q':    case 27: end_flag = 1; break;
  157.  
  158.             case 'A': wn_color_demo();  break;
  159.             case 'B': wn_create_demo(); break;
  160.             case 'C': wn_line_demo();   break;
  161.             case 'D': wn_scroll_demo(); break;
  162.             case 'E': wn_entry_demo();  break;
  163.  
  164.             case 'F':
  165.                 if( EgaVga )
  166.                 {
  167.                     if( Graphics )
  168.                     {
  169.                         if( Graphics )
  170.                             end_g();
  171.                         Graphics = 0;
  172.                         init_video(80,25);
  173.                         end_mouse();
  174.                         init_mouse();
  175.                     }else{
  176.                         init_uw_graphics( 640, 350, 14, 14, -1, -1 );
  177.                         end_mouse();
  178.                         init_mouse();
  179.                         if( Graphics )
  180.                             init_g();
  181.                         mode_switch = 1;
  182.                     }
  183.                 }
  184.                 break;
  185.             case 'G': wn_menu_demo();   break;
  186.             case 'H': wn_font_demo();   break;
  187.             case 'I': wn_print_demo();  break;
  188.  
  189.             case 'J':
  190.                 wn_color_demo();
  191.                 wn_create_demo();
  192.                 wn_line_demo();
  193.                 wn_scroll_demo();
  194.                 wn_entry_demo();
  195.                 wn_menu_demo();
  196.                 wn_font_demo();
  197.                 wn_print_demo();
  198.                 break;
  199.         }
  200.     }
  201.     if( Graphics )
  202.         end_g();
  203.     wn_destroy(wnp);
  204.     end_clock();
  205.     end_mouse();
  206.     end_video();
  207. }
  208.  
  209. void init_g(void)
  210. {
  211. #ifdef __TURBOC__
  212.     int xasp, yasp;            /* Used to read the aspect ratio*/
  213.  
  214.     registerbgidriver(EGAVGA_driver);
  215.  
  216.     GraphDriver = EGA;         /* Request auto-detection    */
  217.     GraphMode = EGAHI;
  218.     initgraph( &GraphDriver, &GraphMode, "" );
  219.     ErrorCode = graphresult();        /* Read result of initialization*/
  220.     if( ErrorCode != grOk ){        /* Error occured during init    */
  221.         printf(" Graphics System Error: %s\n", grapherrormsg( ErrorCode ) );
  222.         exit( 1 );
  223.     }
  224. #endif
  225. #ifdef M_I86
  226.     _setvideomode(_ERESCOLOR);
  227. #endif
  228. }
  229.  
  230. void end_g(void)
  231. {
  232. #ifdef __TURBOC__
  233.     closegraph();
  234. #endif
  235. #ifdef M_I86
  236.     _setvideomode(_DEFAULTMODE);
  237. #endif
  238. }
  239.  
  240. /******************/
  241. /* ~show_graphics */
  242. /*                ***********************************************************/
  243. /* This routine simply show that we really are in graphics mode!!!!         */
  244. /****************************************************************************/
  245. show_graphics()
  246. {
  247.     int i, x;
  248.  
  249.     for( x = i = 0; i < 640; i += 4, x++ )
  250.         setcolor(x % 16), moveto(320, 175), lineto( i, 50 );
  251.     for( x = i = 0; i < 300; i += 4, x++ )
  252.         setcolor(x % 16), moveto(320, 175), lineto( 639, 50 + i );
  253.     for( x = i = 0; i < 640; i += 4, x++ )
  254.         setcolor(x % 16), moveto(320, 175), lineto(640 - i, 349 );
  255.     for( x = i = 0; i < 300; i += 4, x++ )
  256.         setcolor(x % 16), moveto(320, 175), lineto( 0, 350 - i );
  257. }
  258. /*** end of show_graphics ***/
  259.  
  260. /***************/
  261. /* ~wn_3d_plst */
  262. /*             **************************************************************/
  263. /* This is specifically for the demo menu....                               */
  264. /****************************************************************************/
  265. wn_3d_plst(int c, int r, char *str, WINDOW *wnp )
  266. {
  267.     push(wnp->att);
  268.     wn_color( BLACK, BLUE, wnp );
  269.     mv_cs( c + 1, r + 1, wnp );
  270.     wn_qch( strlen(str), 223, wnp );
  271.     mv_cs( c + strlen(str), r, wnp );
  272.     wn_ch(220, wnp);
  273.     pop(wnp->att);
  274.     wn_plst( c, r, str, wnp );
  275. }
  276. /*** end of wn_3d_plst ***/
  277.  
  278. /*****************/
  279. /* ~wn_line_demo */
  280. /*               ************************************************************/
  281. /****************************************************************************/
  282. wn_line_demo()
  283. {
  284.     int i, t, x, y;
  285.     WINDOW wn;
  286.  
  287.     wn_clear(&Main_wn);
  288.     /*----------------- demonstrate line drawing capabilities ----------------*/
  289.     wn_prompt("UltraWin has several border styles...");
  290.     wn_create( 17, 7, 59, 19, SGL_BDR, WN_NORMAL, &wn );
  291.     wn_color( BLACK, CYAN, &wn );
  292.     wn_bdr_color( BLACK, CYAN, &wn );
  293.     wn_set(&wn);
  294.     for( t = 0; t < 3; t++ )
  295.     {
  296.         for( i = 0; i <= 4; i++ )
  297.         {
  298.             wn.bdr_style = i;
  299.             wn_border(&wn);
  300.             wait_ticks(  6L );
  301.         }
  302.     }
  303.     wn_prompt("UltraWin has line drawing capabilities....");
  304.     wn.bdr_style = SGL_BDR;
  305.     wn_border(&wn);
  306.  
  307.     wn_hline(2,DBL_BDR,&wn);
  308.     wait_ticks(  6L );
  309.     wn_hline(4,SGL_BDR,&wn);
  310.     wait_ticks(  6L );
  311.     wn_vline(4,DBL_BDR,&wn);
  312.     wait_ticks(  6L );
  313.     wn_hline(8,DBL_BDR,&wn);
  314.     wait_ticks(  6L );
  315.     wn_vline(40,SGL_BDR,&wn);
  316.     wait_ticks(  6L );
  317.     wn_hline(6,SGL_BDR,&wn);
  318.     wait_ticks(  6L );
  319.     wn_vline(22,SGL_BDR,&wn);
  320.     wait_ticks(  6L );
  321.     wait();
  322.     wn_clear(&wn);
  323.     wn_border(&wn);
  324.     wn_color( YELLOW, CYAN, &wn );
  325.     wn_color( RED, CYAN, &wn );
  326.     wn_plst( 0, 1, "  1     2     3     4     5     6     7 ", &wn );
  327.     wn_plst( 0, 4, "  8     9    10    11    12    13    14 ", &wn );
  328.     wn_plst( 0, 7, " 15     16   17    18    19    20    21 ", &wn );
  329.     wn_plst( 0,10, " 22     23   24    25    26    27    28 ", &wn );
  330.     wn_color( BLACK, CYAN, &wn );
  331.     for( x = 5; x < 40; x += 6 )
  332.         wn_vline(x, SGL_BDR, &wn);
  333.     for( y = 2; y < 11; y += 3 )
  334.         wn_hline(y, SGL_BDR, &wn);
  335.     wn_color( BLUE, LIGHTGRAY, &wn );
  336.     wn.inside = 0;
  337.     wn_plst( 0, 0, "   S     M     T     W     T     F     S   ", &wn );
  338.     wn.inside = 1;
  339.     wait();
  340.     wn_destroy(&wn);
  341. }
  342. /*** end of wn_line_demo ***/
  343.  
  344. /******************/
  345. /* ~wn_entry_demo */
  346. /*                ***********************************************************/
  347. /****************************************************************************/
  348. wn_entry_demo()
  349. {
  350.     int            i, stat, end_flag = OFF,
  351.                     m_att = ((CYAN << 4) | YELLOW),
  352.                     wn_att = ((CYAN << 4) | WHITE),
  353.                     bdr_att = ((CYAN << 4) | BLACK);
  354.     char      *package_m, *package_t, buffer[80];
  355.     WINDOW    wn, *wnp = &wn;
  356.     FIELDS    f;
  357.  
  358.     wn_clear(&Main_wn);
  359. /*---------------------- demonstrate entry capabilities --------------------*/
  360.     wn_prompt("UltraWin has flexible data entry support...");
  361.  
  362.     package_m        = "_";
  363.     package_t        = "#";
  364.   f.input[0]        = Name;
  365.     f.x[0]                = 23, f.y[0] = 10, f.strip[0] = ON;
  366.     f.mask[0]            = "___________________________________";
  367.     f.template[0]    = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
  368.   f.input[1]        = Address;
  369.     f.x[1]                = 23, f.y[1] = 11, f.strip[1] = ON;
  370.     f.mask[1]     = "___________________________________";
  371.     f.template[1] = "***********************************";
  372.     f.input[2]        = City;
  373.     f.x[2]                = 23, f.y[2] = 12, f.strip[2] = ON;
  374.     f.mask[2]     = "____________________";
  375.   f.template[2] = "UAAAAAAAAAAAAAAAAAAA";
  376.   f.input[3]        = State;
  377.     f.x[3]                = 52, f.y[3] = 12, f.strip[3] = ON;
  378.     f.mask[3]     = "__";
  379.     f.template[3] = "UU";
  380.     f.input[4]        = Zip;
  381.     f.x[4]                = 62, f.y[4] = 12, f.strip[4] = ON;
  382.     f.mask[4]     = "_____";
  383.     f.template[4] = "#####";
  384.     f.input[5]        = Phone;
  385.     f.x[5]                = 23, f.y[5] = 13, f.strip[5] = OFF;
  386.     f.mask[5]     = "(___) ___-____";
  387.     f.template[5] = " ###  ### ####";
  388.     f.input[6]        = Password;
  389.     f.x[6]                = 23, f.y[6] = 14, f.strip[6] = ON;
  390.     f.mask[6]     = "________";
  391.     f.template[6] = "AAAAAAAA";
  392.  
  393.     wn_create(2, 4, 77, 23, DBL_BDR, WN_NORMAL, wnp);
  394.     wn.bdr_att = bdr_att;
  395.     wn.att = wn_att;
  396.     wn_name("< UltraWin Order Form >", wnp);
  397.     m_hide();
  398.     add_window(wnp);
  399.     for (i=0; i<6; i++)
  400.         wn_plst(2, i + 1, Enque_strs[i], wnp);
  401.  
  402.     wn_plst(4,   8, "Yes, I want to order package #  at $  .  .  Please mail to:", wnp);
  403.     wn_plst(10, 10, "        Name:", wnp);
  404.     wn_plst(10, 11, "     Address:", wnp);
  405.     wn_plst(10, 12, "        City:                      State:    Zip:", wnp);
  406.     wn_plst(10, 13, "       Phone:", wnp);
  407.     wn_plst(10, 14, "BBS Password:", wnp);
  408.  
  409.     wnp->att = m_att;
  410.     for (i=0; i<7; i++)
  411.     {
  412.         wn_plst(f.x[i], f.y[i], f.mask[i], wnp);
  413.         wn_plst(f.x[i], f.y[i], f.input[i], wnp);
  414.     }
  415.     wnp->att = bdr_att;
  416.     wn_plst(11, 17, "Press <1> or <2> and <Enter>, or press <Esc> to cancel", wnp);
  417.     m_show();
  418.     mv_cs(34, 8, wnp), stat = wn_gets(Package, package_m, package_t, m_att, 1, &wn);
  419.     if ( stat == KEY_ESC )
  420.     {
  421.         m_hide(), remove_window(wnp), m_show();
  422.         return(0);
  423.     }
  424.     m_hide();
  425.     wn_plst(6, 17, "Please enter the following fields, pressing PgDn when complete", wnp);
  426.     wnp->att = m_att;
  427.     f.num_fields = 7;
  428.     Package[0] = '1', Package[1] = 0;
  429.     wn_plst(40, 8, Prices[1], wnp);
  430.     wn_plst(34, 8, Package, wnp);
  431.     wnp->att = bdr_att;
  432.     wn_plst(38, 1, "UltraWin Libraries + Source", wnp);
  433.     wn_plst(38, 2, "  1) Large Model Libraries", wnp);
  434.     wn_plst(38, 3, "  2) Printed Documentation", wnp);
  435.     wn_plst(38, 4, "  3) Example Programs", wnp);
  436.     wn_plst(38, 5, "  4) Support Via the EnQue BBS", wnp);
  437.     wn_plst(38, 6, "  5) Full Source Code!", wnp);
  438.     wnp->att = wn_att;
  439.     m_show();
  440.     i = 0;
  441.     while (!end_flag)
  442.     {
  443.         mv_cs(f.x[i], f.y[i], wnp);
  444.         stat = wn_gets(f.input[i], f.mask[i], f.template[i],
  445.                                      m_att, f.strip[i], wnp);
  446.         switch(stat)
  447.         {
  448.             case KEY_UP:
  449.                 if (--i < 0)
  450.                     i = f.num_fields - 1;
  451.                 break;
  452.           case KEY_ENTER:
  453.                 if (++i >= f.num_fields)
  454.                   end_flag = ON;
  455.                 break;
  456.             case KEY_DN: case KEY_TAB:
  457.                 if (++i >= f.num_fields)
  458.                     i = 0;
  459.               break;
  460.             case KEY_PGUP: case KEY_PGDN:
  461.                 end_flag = ON;
  462.                 break;
  463.             case KEY_ESC: case -1:
  464.                 m_hide(), remove_window(wnp), m_show();
  465.                 return(0);
  466.         }
  467.     }
  468.     m_hide(), remove_window(wnp), m_show();
  469. }
  470.  
  471. /******************/
  472. /* ~wn_color_demo */
  473. /*                ***********************************************************/
  474. /****************************************************************************/
  475. wn_color_demo()
  476. {
  477.     int i, x, xs, ys, new_att, old_att;
  478.     char buff[81];
  479.     uchar palette[16];
  480.     WINDOW *wns[8], *wnp;
  481.     static char *names[8] = { "<< Window 0 >>", "<< Window 1 >>",
  482.      "<< Window 2 >>", "<< Window 3 >>", "<< Window 4 >>",
  483.      "<< Window 5 >>", "<< Window 6 >>", "<< Window 7 >>" };
  484.  
  485.     wn_clear(&Main_wn);
  486.     wn_prompt("Let's demonstrate UltraWin's color capabilities...");
  487.     for( i = 0; i < 8; i++ )
  488.         wns[i] = calloc(1,sizeof(WINDOW));
  489.     for( i = 0; i < 8; i++ )
  490.     {
  491.         wnp = wns[i];
  492.         xs = i * 3 + 12, ys = i + 5;
  493.         wn_create( xs, ys, xs + 31, ys + 9, SGL_BDR, WN_NORMAL, wnp );
  494.         wn_color( WHITE,  i % 8, wnp );
  495.         wn_bdr_color( WHITE, i % 8, wnp );
  496.         sprintf(buff, "<< Window %d >>", i + 1 );
  497.         wn_name(names[i], wnp);
  498.         add_window(wnp);
  499.         for( x = 0; x < 8; x++ )
  500.         {
  501.             sprintf(buff, "Window %d, Line %d", i, x );
  502.             wn_plst( 0, x, buff, wnp );
  503.         }
  504.     }
  505.     for( x = 0; x < 32; x++ )
  506.     {
  507.         for( i = 0; i < 8; i++ )
  508.         {
  509.             new_att = ((((x + i + 1) % 8)) << 4) | WHITE;
  510.             old_att = (((x + i) % 8) << 4) | WHITE;
  511.             wn_bdratt(new_att, wns[i]);
  512.             wn_change_att( new_att, old_att, wns[i] );
  513.         }
  514.     }
  515.     wn_prompt("We can bring any window to the Top...");
  516.     for( i = 7; i >= 0; i-- )
  517.         make_top_window(wns[random(7)]);
  518.     for( i = 7; i >= 0; i-- )
  519.         make_top_window(wns[i]);
  520.     if( EgaVga )
  521.     {
  522.         wn_prompt("We can change the EGA/VGA palette registers...");
  523.         read_palette_all(palette);
  524.         for( i = 0; i < 512; i++ )
  525.             write_palette( random(16), random(64) );
  526.         write_palette_all(palette);
  527.     }
  528.     for( i = 0; i < 8; i++ )
  529.         remove_window(wns[i]);
  530. }
  531. /*** end of wn_color_demo ***/
  532.  
  533. /*******************/
  534. /* ~wn_create_demo */
  535. /*                 **********************************************************/
  536. /****************************************************************************/
  537. wn_create_demo()
  538. {
  539.     int i, j, x, xs, ys, xe, ye;
  540.     char buff[81];
  541.     WINDOW *wns[NUM_WINS], *wnp;
  542.  
  543.     wn_color( YELLOW, BLUE, &Main_wn );
  544.     wn_clear(&Main_wn);
  545.     for( i = 0; i < 10; i++ )
  546.     {
  547.         mv_cs(20, i + 4, &Main_wn);
  548.         wn_printf(&Main_wn, "This is line %d........", i + 1 );
  549.     }
  550.     wn_prompt("Let's dynamically allocate, create, and set 26 POPUP windows.");
  551.     for( x = 0; x < NUM_WINS; x++ )
  552.         if( (wns[x] = calloc(1,sizeof(WINDOW))) == NULL )
  553.             return(0);
  554.     x = 0;
  555.     for( i = 0; i < 5; i++ )
  556.     {
  557.         for( j = 0; j < 4; j++, x++ )
  558.         {
  559.             switch( j )
  560.             {
  561.                 case 0: xs =      i * 6; ys =      i + 3; break;
  562.                 case 1: xs = 60 - i * 6; ys =      i + 3; break;
  563.                 case 2: xs =      i * 6; ys = 20 - i;         break;
  564.                 case 3: xs = 60 - i * 6; ys = 20 - i;          break;
  565.             }
  566.             wnp = wns[x];
  567.             wn_create( xs, ys, xs + 19, ys + 5, SGL_BDR, WN_POPUP,wnp );
  568.             wn_color( WHITE, j + 2, wnp );
  569.             wn_bdr_color( WHITE, j + 2, wnp );
  570.             sprintf(buff, "<< Window %d >>", x + 1 );
  571.             wn_name(buff, wnp);
  572.             wn_set(wnp);
  573.             wn_plst(CENTERED, 0, buff, wnp);
  574.         }
  575.     }
  576.     for( i = 0; i < 12; i += 2, x++ )
  577.     {
  578.         wnp = wns[x];
  579.         xs = 32 - i * 2, ys = 12 - i / 2;
  580.         xe = 47 + i * 2, ye = 15 + i / 2;
  581.         wn_create(xs, ys, xe, ye, SGL_BDR, WN_POPUP, wnp);
  582.         wn_color( WHITE, i % 8, wnp );
  583.         wn_bdr_color( WHITE, i % 8, wnp );
  584.         sprintf(buff, "<< Window %d >>", x + 1 );
  585.         wn_name(buff, wnp);
  586.         wn_set(wnp);
  587.     }
  588.     wn_plst( CENTERED, 5, "Note that these are POPUP windows.", wnp );
  589.     wn_plst( CENTERED, 6, "Everything below them is saved.", wnp );
  590.     wn_plst( CENTERED, 7, "Watch closely as they are removed.", wnp );
  591.     wn_plst( CENTERED, 9, "<<< Don't blink or you will miss it >>>!", wnp );
  592.     wait();
  593.     while( x-- > 0 )
  594.         wn_destroy(wns[x]);
  595.     wn_color( LIGHTGRAY, BLUE, &Main_wn );
  596.     wait();
  597. }
  598. /*** end of wn_create_demo ***/
  599.  
  600. /*******************/
  601. /* ~wn_scroll_demo */
  602. /*                 **********************************************************/
  603. /****************************************************************************/
  604. wn_scroll_demo()
  605. {
  606.     int i, t, x, a, r;
  607.     WINDOW wn, wn1, wn2;
  608.  
  609.     wn_clear(&Main_wn);
  610.     /*--------------------- demonstrate scrolling speed ----------------------*/
  611.     wn_prompt("UltraWin has full window scrolling capabilities....");
  612.     wn_create( 15, 9, 59, 17, SGL_BDR, WN_NORMAL, &wn );
  613.     wn_color( YELLOW, RED, &wn );
  614.     wn_bdr_color( YELLOW, RED, &wn );
  615.     wn_name("Scrolling Window 1", &wn);
  616.     add_window(&wn);
  617.     for( t = 0; t < 2; t++ )
  618.     {
  619.         for( i = 0; i < 100; i++ )
  620.         {
  621.             wn.att &= 0xf0;
  622.             wn.att |= random(16);
  623.             wn_st("UltraWin Library ", &wn );
  624.             if( t == 0 )
  625.             wait_ticks( 1L );
  626.         }
  627.         if( t == 0 )
  628.             wn_prompt("Too slow? Let's try it at full speed!");
  629.     }
  630.     /*------------------------- scroll up and down ---------------------------*/
  631.     wn_prompt("There's more. UltraWin can scroll down...");
  632.     wn_color( YELLOW, RED, &wn );
  633.     wn_clear(&wn);
  634.     for( i = 0; i < 7; i++ )
  635.     {
  636.         mv_cs( 0, i, &wn );
  637.         wn_printf(&wn, "Line %d.....", i + 1 );
  638.     }
  639.     mv_cs(0,0,&wn);
  640.     for( i = 0; i < 7; i++ )
  641.     {
  642.         wn_csr_up(1,&wn);
  643.         wait_ticks(  2L );
  644.     }
  645.     wn_prompt("or UltraWin can scroll up.");
  646.     wn_clear(&wn);
  647.     for( i = 0; i < 7; i++ )
  648.     {
  649.         mv_cs( 0, i, &wn );
  650.         wn_printf(&wn, "Line %d.....", i + 1 );
  651.     }
  652.     for( i = 0; i < 7; i++ )
  653.     {
  654.         wn_csr_dn(1,&wn);
  655.         wait_ticks(  2L );
  656.     }
  657.     /*-------------------------- scrolling regions ---------------------------*/
  658.     wn_prompt("You can also set a scrolling region within a window...");
  659.     wn_color( YELLOW, RED, &wn );
  660.     wn_clear(&wn);
  661.     for( i = 0; i < 7; i++ )
  662.     {
  663.         mv_cs( 0, i, &wn );
  664.         wn_printf(&wn, "Line %d.....", i + 1 );
  665.     }
  666.     wn_scroll_reg( 3, 6, &wn );
  667.     wn_color(WHITE, RED, &wn);
  668.     mv_cs(0, 3, &wn);
  669.     for( i = 0; i < 100; i++ )
  670.     {
  671.         wn_st("UltraWin ", &wn );
  672.         wait_ticks(  2L );
  673.     }
  674.  
  675.     /*-------------------------- scroll multiples ---------------------------*/
  676.     wn_prompt("UltraWin can scroll multiple windows concurrently!");
  677.     wn_create( 12, 12, 49, 18, SGL_BDR, WN_NORMAL, &wn1 );
  678.     wn_color( WHITE, GREEN, &wn1 );
  679.     wn_bdr_color( WHITE, GREEN, &wn1 );
  680.     wn_name("Scrolling Window 2", &wn1);
  681.     wn_create( 18, 4, 69, 14, SGL_BDR, WN_NORMAL, &wn2 );
  682.     wn_color( RED, BLACK, &wn2 );
  683.     wn_bdr_color( RED, BLACK, &wn2 );
  684.     wn_name("Scrolling Window 3", &wn2);
  685.  
  686.     add_window(&wn1);
  687.     add_window(&wn2);
  688.     for( t = 0; t < 2; t++ )
  689.     {
  690.         for( i = 0; i < 100; i++ )
  691.         {
  692.             wn_st("Window 1 output ",&wn);
  693.             wn_st("Window 2 output ",&wn1);
  694.             wn_st("Window 3 output ",&wn2);
  695.             if( t == 0 )
  696.                 wait_ticks(  1L );
  697.         }
  698.         if( t == 0 )
  699.             wn_prompt("Too slow? Let's try it at full speed!");
  700.     }
  701.     /*----------------- scroll multiples while moving! -----------------------*/
  702.     wn_prompt("UltraWin can scroll multiple windows while moving!");
  703.     for( i = 0; i < 50; i++ )
  704.     {
  705.         wn_st("Window 1 output ",&wn);
  706.         wn_st("Window 2 output ",&wn1);
  707.         wn_st("Window 3 output ",&wn2);
  708.         x = random(10);
  709.         if( x == 1 )
  710.         {
  711.             if( wn.pane.x_min > 0 )
  712.                 wn.pane.x_min--, wn.pane.x_max--, r = 1;
  713.         }
  714.         else if( x == 2 )
  715.         {
  716.             if( wn1.pane.y_min > 4 )
  717.                 wn1.pane.y_min--, wn1.pane.y_max--, r = 1;
  718.             if( wn1.pane.x_max < V_cols )
  719.                 wn1.pane.x_min++, wn1.pane.x_max++, r = 1;
  720.         }
  721.         else if( x == 3 )
  722.         {
  723.             if( wn2.pane.y_max < V_rows )
  724.                 wn2.pane.y_min++, wn2.pane.y_max++, r = 1;
  725.             if( wn2.pane.x_max < V_cols )
  726.                 wn2.pane.x_min++, wn2.pane.x_max++, r = 1;
  727.         }
  728.         if( r )
  729.         {
  730.             reset_all_masks();                    /* reset all masks and redraw all windows */
  731.             refresh_desktop();             /* since we are moving windows NOT on top */
  732.         }                               /* if the window was always on top, we can*/
  733.     }                                  /* simply use move_wn_up, etc...                    */
  734.     remove_window(&wn);
  735.     remove_window(&wn1);
  736.     remove_window(&wn2);
  737. }
  738. /*** end of wn_scroll_demo ***/
  739.  
  740. /**************/
  741. /* ~wn_prompt */
  742. /*            ***************************************************************/
  743. /****************************************************************************/
  744. wn_prompt( char *prompt )
  745. {
  746.     WINDOW wn;
  747.  
  748.     wn_create( 0, 0, 79, 2, DBL_BDR, WN_NORMAL, &wn );
  749.     wn_color( RED, LIGHTGRAY, &wn );
  750.     wn_bdr_color( LIGHTGRAY, BLACK, &wn );
  751.     wn_set(&wn);
  752.     wn_plst( CENTERED, 0, prompt, &wn );
  753.     wait();
  754.     wn_destroy(&wn);
  755. }
  756. /*** end of wn_prompt ***/
  757.  
  758. /*********/
  759. /* ~wait */
  760. /*       ********************************************************************/
  761. /****************************************************************************/
  762. wait()
  763. {
  764.     push(Main_wn.att);
  765.     wn_color( LIGHTGRAY, RED, &Main_wn );
  766.     mv_cs(0,21,&Main_wn);
  767.     wn_cleol(&Main_wn);
  768.     wn_plst(CENTERED, 21, "Hit any key to continue...", &Main_wn);
  769.     wait_event();
  770.     pop(Main_wn.att);
  771.     mv_cs(0,21,&Main_wn);
  772.     wn_cleol(&Main_wn);
  773. }
  774. /*** end of wn_prompt ***/
  775.  
  776. /*****************/
  777. /* ~title_screen */
  778. /*               ************************************************************/
  779. /* This routine does the UltraCom title screen, logo and subscription info    */
  780. /****************************************************************************/
  781. char    *Title_strs[10] =
  782. {
  783. " ██    ██  ██  ████████  ████████  ████████     ██     ██  ██  ███     ██   ",
  784. " ██▒   ██▒ ██▒  ▒▒██▒▒▒▒ ██▒▒▒▒██▒ ██▒▒▒▒██▒    ██▒    ██▒ ██▒ ████░   ██▒  ",
  785. " ██▒░  ██▒░██▒░  ░██▒░░░░██▒░░░██▒░██▒░░░██▒░   ██▒░   ██▒░██▒░██▒██░  ██▒░ ",
  786. " ██▒░  ██▒░██▒░   ██▒░   ██▒░  ██▒░██▒░  ██▒░   ██▒░   ██▒░██▒░██▒░██░ ██▒░ ",
  787. " ██▒░  ██▒░██▒░   ██▒░   ████████▒░████████▒░   ██▒░   ██▒░██▒░██▒░ ██░██▒░ ",
  788. " ██▒░  ██▒░██▒░   ██▒░   ██▒▒██▒▒▒░██▒▒▒▒██▒░   ██▒░   ██▒░██▒░██▒░  ████▒░ ",
  789. " ██▒░  ██▒░██▒░   ██▒░   ██▒░░██░░░██▒░░░██▒░   ██▒███ ██▒░██▒░██▒░  ████▒░ ",
  790. "  ██████▒▒░█████  ██▒░   ██▒░  ██  ██▒░  ██▒░    ███▒███▒▒░██▒░██▒░    ██▒░ ",
  791. "   ▒▒▒▒▒▒░░ ▒▒▒▒▒  ▒▒░    ▒▒░   ▒▒  ▒▒░   ▒▒░     ▒▒▒ ▒▒▒░░ ▒▒░ ▒▒░     ▒▒░ ",
  792. "    ░░░░░░   ░░░░░  ░░     ░░    ░░  ░░    ░░      ░░░ ░░░   ░░  ░░      ░░ "
  793. };
  794. char    *Wave_strs[7] =
  795. {
  796. "            Source Available          Extended Mode Support                 ",
  797. "                      EGA/VGA Downloadable Fonts             Small          ",
  798. " ┌─────────┐      ╔═ Menus═╗     [Data Entry]                  │            ",
  799. " │ Windows │      ║1) Small║        $12.34              Fast───┼───Flexible ",
  800. " └─────────┘      ║2) Fast ║        09/29/90                   │            ",
  801. "                  ╚════════╝     (123) 555-1212            Compatible       ",
  802. "   Buffered Windows  Background Printing     Mouse Support                  "
  803. };
  804. char    *Info_strs[5] =
  805. {
  806. "UltraWin! Version 2.00 by EnQue Software (Kevin Huck and Boyd Gafford)",
  807. "Please send $39.95 registration fee for printed documentation and source to",
  808. "EnQue Software ",
  809. "Route #1, Box 116C ",
  810. "Pleasant Hill, Mo. 64080"
  811. };
  812. title_screen()
  813. {
  814.     register    int i, r, c, c1 = 7, c2 = (c1 + 9) % 16;
  815.     int                x_off = (V_cols / 2) - 39;
  816.     int                y_off = (V_rows / 2) - 8;
  817.     int                len = strlen(Wave_strs[0]);
  818.     int                w_off = 0;
  819.     WINDOW        u_wn, b_wn;
  820.     uchar            b = 0, *mask, *src;
  821.     char            temp_str[40], palette_save[17];
  822.  
  823.     wn_create(x_off, y_off, x_off + 77, y_off + 13, DBL_BDR, WN_POPUP, &b_wn);
  824.     b_wn.att = b_wn.bdr_att = (c1 << 4) | WHITE;
  825.     wn_set( &b_wn);
  826.     wn_create(x_off, y_off, x_off + 77, y_off + 13, NO_BDR, WN_NORMAL, &u_wn);
  827.     u_wn.att = u_wn.bdr_att = (c1 << 4) | c2;
  828.     wn_set( &u_wn);
  829.   wn_border(&b_wn);
  830.     u_wn.scroll = b_wn.scroll = OFF;
  831.     mv_cs(1, 1, &u_wn);
  832.     wn_qch(len, ' ', &u_wn);
  833.     for (i=0; i<10; i++)
  834.         wn_plst(1, i + 2, Title_strs[i], &u_wn);
  835.     mv_cs(1, 12, &u_wn);
  836.     wn_qch(len, ' ', &u_wn);
  837.  
  838.     mask = b_wn.mask;
  839.     src =  u_wn.buff;
  840.     for( r = 0; r < b_wn.rows; r++ )
  841.         for( c = 0; c < b_wn.cols; c++, mask++, src+=2 )
  842.             if ( ((*src != ' ') && (*src != 0)) )
  843.                 *mask += 1;
  844.     b_wn.mask_on = ON;
  845.     for (i=0; i<5; i++)
  846.         wn_plst(CENTERED, 16 + i, Info_strs[i], &Main_wn);
  847.     if( EgaVga )
  848.         read_palette_all(palette_save);
  849.     while ( !check_key() )
  850.     {
  851.         if( !(Tics % 5) )
  852.         {
  853.             if( !(Tics % 10) )
  854.                 write_palette(random(15),random(64));
  855.             if ((++b) >= len)
  856.             {
  857.                 b = 0;
  858.                 c1 = (c1 + 1) % 8;
  859.                 c2 = (c1 + 9) % 16;
  860.                 b_wn.att = b_wn.bdr_att = (c1 << 4) | WHITE;
  861.                 wn_border(&b_wn);
  862.                 u_wn.att = (c1 << 4) | c2;
  863.                 mv_cs(1, 1, &u_wn);
  864.                 wn_qch(len, ' ', &u_wn);
  865.                 for (i=0; i<10; i++)
  866.                     wn_plst(1, i + 2, Title_strs[i], &u_wn);
  867.                 mv_cs(1, 12, &u_wn);
  868.                 wn_qch(len, ' ', &u_wn);
  869.                 if( ++w_off >= 6 )
  870.                     w_off = 0;
  871.                 write_palette(random(15),random(64));
  872.             }
  873.             for( i = 0; i < 7; i++ )
  874.             {
  875.                 mv_cs(0, i + w_off, &b_wn);
  876.                 if (len - b)
  877.                     wn_st_qty(&Wave_strs[i][b], len - b, &b_wn);
  878.                 if (b)
  879.                     wn_st_qty(&Wave_strs[i][0], b, &b_wn);
  880.             }
  881.         }
  882.     }
  883.     if( EgaVga )
  884.         write_palette_all(palette_save);
  885.     wait_event();
  886.     wn_clear(&u_wn);
  887.     wn_border(&b_wn);
  888.     for( i = 0; i < 7; i++ )
  889.         wn_plst(1, i + 3, &Wave_strs[i][0], &u_wn);
  890.     wait();
  891.     wn_clear(&Main_wn);
  892.     wn_destroy(&u_wn);
  893.     wn_destroy(&b_wn);
  894. }
  895.  
  896. /*****************/
  897. /* ~wn_menu_demo */
  898. /*               ************************************************************/
  899. /* This routine demonstrates UltraWin's menuing capabilities...                         */
  900. /* the main polling loop!                                                                                                        */
  901. /****************************************************************************/
  902. wn_menu_demo()
  903. {
  904.     int id, i,
  905.             back_att    = (LIGHTGRAY << 4) | BLACK,
  906.             bdr_att        = (LIGHTGRAY << 4) | BLACK,
  907.             csr_att        = (CYAN << 4) | YELLOW,
  908.             first_att    = (LIGHTGRAY << 4) | RED;
  909.  
  910.     wn_clear(&Main_wn);
  911. /*--------------------- demonstrate menuing capabilities -------------------*/
  912.     wn_prompt("Use the arrow keys or your mouse to traverse the menu tree!");
  913.  
  914. /*-------------------------- create top menu -------------------------------*/
  915.     menu_create(0, 4, V_cols - 1, 3, M_HORIZONTAL,
  916.                             back_att, bdr_att, csr_att, first_att,
  917.                             NO_BDR, WN_NORMAL, Top_mnp);
  918.     item_add( "   Files   ", 1, 3, &Top_menu );
  919.     item_add( " Terminals ", 2, 1, &Top_menu );
  920.     item_add( "   Setup   ", 3, 3, &Top_menu );
  921.     item_add( "  Windows  ", 4, 2, &Top_menu );
  922.  
  923.     Drop_mnps[0] = &Files_menu;
  924.     Drop_mnps[1] = &Terminal_menu;
  925.     Drop_mnps[2] = &Setup_menu;
  926.     Drop_mnps[3] = &Window_menu;
  927. /*------------------------- create file menu -------------------------------*/
  928.     menu_create(0, 5, 21, 12, M_VERTICAL,
  929.         back_att, bdr_att, csr_att, first_att,
  930.         SGL_BDR, WN_NORMAL, Drop_mnps[0]);
  931.     item_add( " Text Editor   Alt-E",    5, 6, &Files_menu );
  932.     item_add( " Hex Editor    Alt-H",    6, 1, &Files_menu );
  933.     item_add( " File Manager  Alt-F",    7, 1, &Files_menu );
  934.     item_add( " Calculator    Alt-C",    8, 1, &Files_menu );
  935.     item_add( " Dos Shell     Alt-O",    9, 5, &Files_menu );
  936.     item_add( " Quit          Alt-Q",10, 1, &Files_menu );
  937.  
  938. /*------------------------ create terminal menu ----------------------------*/
  939.     menu_create(11, 5, 32, 11, M_VERTICAL,
  940.      back_att, bdr_att, csr_att, first_att, SGL_BDR, WN_NORMAL, Drop_mnps[1]);
  941.     item_add( " Add Terminal  Alt-T",     11, 1, &Terminal_menu );
  942.     item_add( " Settings      Alt-F6", 12, 1, &Terminal_menu );
  943.     item_add( " Receive File  Alt-F7", 13, 1, &Terminal_menu );
  944.     item_add( " Transmit File Alt-F8", 14, 1, &Terminal_menu );
  945.     item_add( " Comm Status   Alt-S",     15, 6, &Terminal_menu );
  946.  
  947. /*--------------------------- create setup menu ----------------------------*/
  948.     menu_create(22, 5, 43,10, M_VERTICAL,
  949.         back_att, bdr_att, csr_att, first_att, SGL_BDR, WN_NORMAL, Drop_mnps[2]);
  950.     item_add( " Mouse Setup        ",    16, 1, &Setup_menu);
  951.     item_add( " Video Mode    Alt-V", 17, 1, &Setup_menu );
  952.     item_add( " Window Color  Alt-W",    18, 1, &Setup_menu );
  953.     item_add( " Border Color  Alt-B", 19, 1, &Setup_menu );
  954.  
  955. /*--------------------------- create window menu ---------------------------*/
  956.     menu_create(33, 5, 48, 9, M_VERTICAL,
  957.         back_att, bdr_att, csr_att, first_att,  SGL_BDR, WN_NORMAL, Drop_mnps[3]);
  958.     item_add( " Delete  Alt-D",    20, 1, &Window_menu );
  959.     item_add( " Size    Alt-S",    21, 1, &Window_menu );
  960.     item_add( " Move    Alt-M",    22, 1, &Window_menu );
  961.  
  962. /*------------------------------ let's roll --------------------------------*/
  963.     wn_create( 0, 4, V_cols - 1, V_rows - 4, SGL_BDR, WN_NORMAL, Back_wnp );
  964.     wn_color( WHITE, RED, Back_wnp );
  965.     wn_bdr_color( WHITE, RED, Back_wnp );
  966.     add_window(Back_wnp);
  967.     wn_plst(0,0, "UltraWin is a powerful, easy to use window library", Back_wnp);
  968.     wn_plst(0,1, "with flexible data entry and menu capabilities... ", Back_wnp);
  969.  
  970.     menu_set(Top_mnp);
  971.     m_show();
  972.     set_idle_func(tmp);
  973.     id = menu_system(Top_mnp, Drop_mnps, 0);
  974.     set_idle_func(NULL);
  975.  
  976.     m_hide();
  977.     menu_restore(Top_mnp);
  978.     menu_destroy(Top_mnp);                                                        /* destroy all menus!        */
  979.     for( i = 0; i < 4; i++ )
  980.         menu_destroy(Drop_mnps[i]);
  981.     remove_window(Back_wnp);                                                    /* background window    */
  982.     return(id);
  983. }
  984. /*** end of wn_menu_demo ***/
  985.  
  986. int tmp()
  987. {
  988.     int att;
  989.  
  990.     if( !(Tics % 10) )
  991.     {
  992.         att = Back_wnp->att & 0x0f;                                            /* roll through colors  */
  993.         att = (att + 1) % 16;
  994.         if( att == RED )
  995.             att = (att + 1) % 16;
  996.         Back_wnp->att &= 0xf0;
  997.         Back_wnp->att |= att;
  998.         m_hide();
  999.         wn_st("UltraWin Library. Power, Speed, Ease!   ", Back_wnp );
  1000.         m_show();
  1001.     }
  1002. }
  1003.  
  1004. /******************/
  1005. /* ~wn_change_att */
  1006. /*                ***********************************************************/
  1007. /* This routine changes the color of a window...                                        */
  1008. /* This demonstrates low level window control...                                                        */
  1009. /****************************************************************************/
  1010. wn_change_att(int new_att, int old_att, WINDOW *wnp)
  1011. {
  1012.     int i, cnt;
  1013.     uchar *dest = wnp->buff;
  1014.     old_att  = get_att(old_att);
  1015.     new_att  = get_att(new_att);
  1016.  
  1017.     cnt = wnp->rows * wnp->cols;
  1018.     dest++;
  1019.     for( i = 0; i < cnt; i++, dest += 2 )
  1020.         if( *dest == old_att )
  1021.             *dest = new_att;
  1022.     wn_border( wnp );
  1023.     wn_rfsh( wnp );
  1024. }
  1025. /*** end of wn_change_att ***/
  1026.  
  1027. /*****************/
  1028. /* ~wn_font_demo */
  1029. /*               ************************************************************/
  1030. /* This routine shows the various font capabilities in EGA/VGA...                      */
  1031. /****************************************************************************/
  1032. extern int G_opt;
  1033. wn_font_demo()
  1034. {
  1035.     int i, r, c, x;
  1036.     WINDOW wn;
  1037.  
  1038.     push(Font_spacing);
  1039.     wn_clear(&Main_wn);
  1040.     if( (Font8x14 = calloc(256,14)) == NULL )
  1041.     {
  1042.         wn_printf(&Main_wn,"Sorry, not enough memory to allocate font!");
  1043.         wait();
  1044.         return(0);
  1045.     }
  1046.     if( !EgaVga )
  1047.     {
  1048.         wn_plst( CENTERED, 3,
  1049.             "Sorry, cannot demonstrate fonts on a non-EGA/VGA compatible adapter",
  1050.             &Main_wn );
  1051.         wait_ticks(18L*3L);
  1052.         return(0);
  1053.     }
  1054.     /*------------------- demonstrate font capabilities... -------------------*/
  1055.     wn_prompt("UltraWin has multiple text font capabilities....");
  1056.     wn_create( 30, 4, 50, 23, SGL_BDR, WN_NORMAL, &wn );
  1057.     wn_color( YELLOW, RED, &wn );
  1058.     wn_bdr_color( LIGHTGRAY, RED, &wn );
  1059.     wn_name("Font Window", &wn);
  1060.     add_window(&wn);
  1061.  
  1062.     G_opt = OFF;
  1063.     for( i = 0; i < 4; i++ )
  1064.     {
  1065.         wn_clear(&wn);
  1066.         switch( i )
  1067.         {
  1068.             case 1:
  1069.                 setmem( Font8x14, 256*14, 0 );
  1070.                 install_font( Font8x14, 0, 0, 256, 14, 0 );
  1071.                 rom8x8(0,0);
  1072.                 break;
  1073.             case 2:
  1074.                 rom8x14(0,0);
  1075.                 break;
  1076.             case 3:
  1077.                 wn_plst(CENTERED, 0, "Now we have 512 unique characters on the screen at one time!", &Main_wn);
  1078.                 load_font( Font8x14, "8x14icon.fnt" );
  1079.                 if( Vga )
  1080.                         rom8x14(0,1), rom8x14(1,1), mv_csr(0,80);
  1081.                 install_font( Font8x14, 1, 0, 256, 14, 0 );
  1082.                 set_block_ab(0,1);
  1083.                 break;
  1084.         }
  1085.         Font_spacing = 14;
  1086.         for( x = r = 0; r < 16; r++ )
  1087.             for( c = 0; c < 16; c++,x++ )
  1088.                 mv_cs( c, r, &wn ), wn_ch(x,&wn);
  1089.         if( Graphics )
  1090.             rom8x14(0,0);
  1091.         wait();
  1092.     }
  1093.     G_opt = ON;
  1094.     if( Vga )
  1095.         rom8x16(0,1), rom8x16(1,1), mv_csr(0,80);
  1096.   else
  1097.         rom8x14(0,0);
  1098.     set_block_ab(0,0);
  1099.     free(Font8x14);
  1100.     remove_window(&wn);
  1101.     pop(Font_spacing);
  1102. }
  1103. /*** end of wn_font_demo ***/
  1104.  
  1105. /******************/
  1106. /* ~wn_print_demo */
  1107. /*                ***********************************************************/
  1108. /*                                                                          */
  1109. /* Here we demostrate the capabilities of the background/dynamic printing   */
  1110. /* routines...                                                              */
  1111. /*                                                                          */
  1112. /* NOTE: All output will be directed to DOS files "out1.prt" & "out2.prt"   */
  1113. /*                                                                          */
  1114. /*                                                                          */
  1115. /* 1) First we set up a 1k ram based print queue that is allowed to "grow"  */
  1116. /*    up to 8k.  As the queue is emptied, it automatically shrinks,        */
  1117. /*    thereby minimizing memory usage. Note that the queue can be setup     */
  1118. /*    with an initial size equal to it's maximum size so that the dynamic   */
  1119. /*    sizing does not occur.                                                */
  1120. /*                                                                          */
  1121. /* 2) Next, we use a 128k disk based queue, requiring no memory, save a     */
  1122. /*    small amount of stack space, and print out the exact same data...     */
  1123. /*                                                                                                                                                    */
  1124. /* 3) Last, but not least, we will output to both the ram based and disk    */
  1125. /*    based queues at the same time!                                        */
  1126. /****************************************************************************/
  1127. wn_print_demo()
  1128. {
  1129.     int i, r, c, pi, x;
  1130.     char buffer[81];
  1131.     ulong start, end;
  1132.     long secs;
  1133.     PRINT *p[2];
  1134.  
  1135.     wn_clear(&Main_wn);
  1136.     wn_prompt("UltraWin has background printing support!");
  1137.  
  1138.     wn_plst( CENTERED, 2, "Welcome to the UltraWin Printer Facilities!", &Main_wn );
  1139.     wn_plst( CENTERED, 4, "This demo will setup two printers, both    ", &Main_wn );
  1140.     wn_plst( CENTERED, 5, "outputting to DOS files.  The first one is ", &Main_wn );
  1141.     wn_plst( CENTERED, 6, "a dynamically sizing ram queue that will   ", &Main_wn );
  1142.     wn_plst( CENTERED, 7, "grow up to 8k, and shrink back to 1k when  ", &Main_wn );
  1143.     wn_plst( CENTERED, 8, "drained.  Ram based queues can be up to    ", &Main_wn );
  1144.     wn_plst( CENTERED, 9, "64k.  The second is a 32k disk based queue ", &Main_wn );
  1145.     wn_plst( CENTERED,10, "that requires virtually no memory at all.  ", &Main_wn );
  1146.     wn_plst( CENTERED,11, "Queues of this nature can be of any size up", &Main_wn );
  1147.     wn_plst( CENTERED,12, "to 2 Gigabytes!  First we will print 8k    ", &Main_wn );
  1148.     wn_plst( CENTERED,13, "to each queue separately, then to both     ", &Main_wn );
  1149.     wn_plst( CENTERED,14, "concurrently.  Watch the status update as  ", &Main_wn );
  1150.     wn_plst( CENTERED,15, "the data is printed in the background.     ", &Main_wn );
  1151.  
  1152. /*--------- initialize both a ram based and disk based print queue ---------*/
  1153.     if( !init_printer("out1.prt", NULL, 1024L, 8192L, &Printer1) )
  1154.         tone(1024,10);
  1155.     if( !init_printer("out2.prt", "disk.buf", 32768L, 32768L, &Printer2) )
  1156.         tone(1024,10);
  1157.     p[0] = &Printer1;
  1158.     p[1] = &Printer2;
  1159.     set_idle_func(print_in_bkgrnd);                /* wait event will call this for us */
  1160.     wait();
  1161.  
  1162.     for( i = 0; i < 2; i++ )
  1163.     {
  1164.         wn_create( 2, 6 + (i*8) + i, V_cols-3, 12 + (i*8) + i, SGL_BDR, WN_POPUP, &Print_wn[i] );
  1165.         wn_color( LIGHTGRAY, RED, &Print_wn[i] );
  1166.         wn_bdr_color( LIGHTGRAY, RED, &Print_wn[i] );
  1167.         sprintf( buffer, "Printer %d", i + 1 );
  1168.         wn_name(buffer, &Print_wn[i]);
  1169.         add_window(&Print_wn[i]);
  1170.     }
  1171. /*----------------------------- perform steps 1&2 --------------------------*/
  1172.     for( x = 0; x < 2; x++ )
  1173.     {
  1174.         wn_clear( &Main_wn);
  1175.         start = Tics;
  1176.         wn_plst( CENTERED, 2, "Queueing 8K bytes of data...", &Main_wn );
  1177.         p[x]->block_mode = 1;
  1178.         i = 0;
  1179.         disp_print_stats( p[x], 1, &Print_wn[x] );
  1180.         while( p[x]->cnt < 8000L )
  1181.         {
  1182.             sprintf( buffer, "This is line %4d \r", i++ );
  1183.             print_str( buffer, p[x] ), print_eol( p[x] );
  1184.             if( i % 100 )
  1185.                 disp_print_stats( p[x], 0, &Print_wn[x] );
  1186.             else
  1187.                 disp_print_stats( p[x], 1, &Print_wn[x] );
  1188.         }
  1189.         wn_st( "done!", &Main_wn );
  1190.         wn_plst( CENTERED, 3, "Now lets print the data...", &Main_wn );
  1191.         c = 0;
  1192.         while( (p[x]->cnt > 0L)  )
  1193.         {
  1194.             if( check_key() )
  1195.             {
  1196.                 get_key();
  1197.                 mv_cs( c++, 4, &Main_wn );
  1198.                 wn_ch( Event.key, &Main_wn );
  1199.             }
  1200.             print_in_bkgrnd();            /* this would be called automatically if we   */
  1201.                                                             /* called wait event. Otherwise, call it as   */
  1202.                                                             /* often as you can to perform printer output.*/
  1203.             disp_print_stats( p[x], 0, &Print_wn[x] );
  1204.         }
  1205.         disp_print_stats( p[x], 1, &Print_wn[x] );
  1206.         wn_plst( CENTERED, 3, "  Now lets print the data...done!  ", &Main_wn );
  1207.         end = Tics;
  1208.         mv_cs( 20, 1, &Main_wn );
  1209.         secs = ((end - start) * 100L) / 91L;
  1210.         wn_printf( &Main_wn, "Time: = ~%ld.%02ld seconds  ~%-5d bytes/sec",
  1211.             secs / 100L, secs % 100L, (int)(800000L/secs) );
  1212.         wait();
  1213.     }
  1214. /*------------------------------- perform steps 3 --------------------------*/
  1215.     wn_clear( &Main_wn);
  1216.     start = Tics;
  1217.     wn_plst( CENTERED, 2, "Queueing 8K bytes of data...", &Main_wn );
  1218.     i = 0;
  1219.     disp_print_stats( p[0], 1, &Print_wn[0] );
  1220.     disp_print_stats( p[1], 1, &Print_wn[1] );
  1221.     while( p[0]->cnt < 8000L )
  1222.     {
  1223.         sprintf( buffer, "This is line %4d \r", i++ );
  1224.         print_str( buffer, p[0] ), print_eol( p[0] );
  1225.         print_str( buffer, p[1] ), print_eol( p[1] );
  1226.         if( i % 100 )
  1227.         {
  1228.             disp_print_stats( p[0], 0, &Print_wn[0] );
  1229.             disp_print_stats( p[1], 0, &Print_wn[1] );
  1230.         }else{
  1231.             disp_print_stats( p[0], 1, &Print_wn[0] );
  1232.             disp_print_stats( p[1], 1, &Print_wn[1] );
  1233.         }
  1234.     }
  1235.     wn_st( "done!", &Main_wn );
  1236.     wn_plst( CENTERED, 3, "Now lets print the data...", &Main_wn );
  1237.     c = 0;
  1238.     while( (p[0]->cnt > 0L) || (p[1]->cnt > 0L) )
  1239.     {
  1240.         if( check_key() )
  1241.         {
  1242.             get_key();
  1243.             mv_cs( c++, 1, &Main_wn );
  1244.             wn_ch( Event.key, &Main_wn );
  1245.         }
  1246.         print_in_bkgrnd();                /* this would be called automatically if we   */
  1247.                                                             /* called wait event. Otherwise, call it as   */
  1248.                                                             /* often as you can to perform printer output.*/
  1249.         disp_print_stats( p[0], 0, &Print_wn[0] );
  1250.         disp_print_stats( p[1], 0, &Print_wn[1] );
  1251.     }
  1252.     disp_print_stats( p[0], 1, &Print_wn[0] );
  1253.     disp_print_stats( p[1], 1, &Print_wn[1] );
  1254.     wn_plst( CENTERED, 3, "  Now lets print the data...done!  ", &Main_wn );
  1255.     end = Tics;
  1256.     mv_cs( 20, 1, &Main_wn );
  1257.     secs = ((end - start) * 100L) / 91L;
  1258.     wn_printf( &Main_wn, "Time: = ~%ld.%02ld seconds  ~%-5d bytes/sec",
  1259.         secs / 100L, secs % 100L, (int)(1600000L/secs) );
  1260.     wait();
  1261. /*--------------------------------------------------------------------------*/
  1262.  
  1263.     remove_window(&Print_wn[0]);
  1264.     remove_window(&Print_wn[1]);
  1265.     end_printer( &Printer1 );
  1266.     end_printer( &Printer2 );
  1267.     wn_clear(&Main_wn);
  1268. }
  1269. /*** end of wn_print_demo ***/
  1270.  
  1271. /*********************/
  1272. /* ~disp_print_stats */
  1273. /*                   *******************************************************/
  1274. /*  This routine prints important variables in the printer structure to the*/
  1275. /*    desired window and is used primarily for debugging.  If the mode is    */
  1276. /*    1, all variables are printed, if 0, only the Read, Write, and Cnt are  */
  1277. /*    printed for speed.                                                     */
  1278. /*                                                                         */
  1279. /* Device:lpt1                                  Buffer:   disk.buf         */
  1280. /* Read  :    4343     Init Size:     2000      Active:1      CR  :1       */
  1281. /* Write :    6648     Max  Size:    32000      Halt  :1      LF  :2       */
  1282. /* Cnt   :    2345     Curr Size:    16000      Block :1      Xlat:0       */
  1283. /***************************************************************************/
  1284. void disp_print_stats( PRINT *p, int mode, WINDOW *wnp )
  1285. {
  1286.     mv_cs( 0, 1, wnp );
  1287.     wn_printf( wnp, "Read  :%8ld", p->read  );
  1288.     mv_cs( 0, 2, wnp );
  1289.     wn_printf( wnp, "Write :%8ld", p->write );
  1290.     mv_cs( 0, 3, wnp );
  1291.     wn_printf( wnp, "Cnt   :%8ld", p->cnt   );
  1292.     if( mode )
  1293.     {
  1294.         mv_cs( 0, 0, wnp );
  1295.         wn_printf( wnp, "Device:%-20s   Buffer:%-20s", p->device, p->buffer );
  1296.         mv_cs( 20, 1, wnp );
  1297.         wn_printf( wnp, "Init Size:%8ld    Active:%d    CR  :%d",
  1298.             p->init_que_size, p->active, p->cr_cnt );
  1299.         mv_cs( 20, 2, wnp );
  1300.         wn_printf( wnp, "Max  Size:%8ld    Halt  :%d    LF  :%d",
  1301.             p->max_que_size, p->halt, p->lf_cnt  );
  1302.         mv_cs( 20, 3, wnp );
  1303.         wn_printf( wnp, "Curr Size:%8ld    Block :%d    Xlat:%d",
  1304.             p->curr_que_size, p->block_mode, p->xlat_flag );
  1305.     }
  1306. }
  1307. /*** end of disp_print_stats ***/
  1308.  
  1309. /**** END OF FILE ****/
  1310.  
  1311.